﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using GRWL.BZSC.UI.BaseDataSvc;

namespace GRWL.BZSC.UI
{
    public partial class BaseFrm : BaseClass.BaseForm
    {
        /// <summary>
        /// 定义日志对象
        /// </summary>
        public static log4net.ILog LOG = log4net.LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);

        /// <summary>
        /// 业务数据接口代理
        /// </summary>
        public BaseDataSvc.BaseDataClient BaseDataProxy = null;

        /// <summary>
        /// 记住当前设置的编码规则
        /// </summary>
        public CodeRuleFrm.CodeRule codeRule { get; set; }

        /// <summary>
        /// 单据编号字头
        /// </summary>
        public string BillPrefix;

        // 单据编辑状态
        private GRWL.BZSC.UI.Common.BillOperateType _EditStatus;

        /// <summary>
        /// 单据编辑状态
        /// </summary>
        public GRWL.BZSC.UI.Common.BillOperateType EditStatus
        {
            get
            {
                return _EditStatus;
            }
            set
            {
                _EditStatus = value;
                EditStatusChanged();
            }
        }

        public virtual void EditStatusChanged()
        {
            //编辑状态转换后的处理代码放置此处
        }

        public BaseFrm()
        {
            InitializeComponent();                
        }

        protected override void OnFormClosed(FormClosedEventArgs e)
        {
            base.OnFormClosed(e);
            if (this.BaseDataProxy != null)
            {
                if (this.BaseDataProxy.State != System.ServiceModel.CommunicationState.Closed && this.BaseDataProxy.State != System.ServiceModel.CommunicationState.Faulted)
                {
                    this.BaseDataProxy.Close();
                }
                this.BaseDataProxy = null;
            }
            if (LOG != null)
                LOG = null;
        }

        // 按Enter后下一输入控件自动获取焦点
        private void BaseFrm_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Return)
            {
                SelectNextControl(this.ActiveControl,true,true,true,true);
                e.Handled = true;
            }
        }
    }
}
